/**************************************************************************************
*
*	Copyright (C) 2011 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	ScreenOverlay.cpp
*
*	Comments	-	See ScreenOverlay.h
*
**************************************************************************************/

#include "../Include/ScreenOverlay.h"

#ifdef PSX_PLATFORM_WINDOWS_WINDOW

#include "../Include/GraphicsResourceManager.h"
#include "../Include/String.h"

namespace Pulse
{

	ScreenOverlay::ScreenOverlay( FLOAT x, FLOAT y, FLOAT width, FLOAT height )
		: m_pos( x, y ), m_size( width, height ), m_pVB( PSX_NULL ), m_pMaterial( PSX_NULL )
	{

	}

	ScreenOverlay::~ScreenOverlay( void )
	{

	}

	EErrorCode::Type ScreenOverlay::Initialize( void )
	{
		FLOAT widthEps = 0.5f / m_size.x;
		FLOAT heightEps = 0.5f / m_size.y;

		Vertex2D quad[4] = {
			{
				Vector3( m_pos.x, m_pos.y, 0.5f ),
				0xFFFFFFFF,
				Vector2( widthEps, heightEps )
			},
			{
				Vector3( m_pos.x + 1.0f, m_pos.y, 0.5f ),
				0xFFFFFFFF,
				Vector2( 1.0f + widthEps, heightEps )
			},
			{
				Vector3( m_pos.x + 1.0f, m_pos.y + 1.0f, 0.5f ),
				0xFFFFFFFF,
				Vector2( 1.0f + widthEps, 1.0f + heightEps )
			},
			{
				Vector3( m_pos.x, m_pos.y + 1.0f, 0.5f ),
				0xFFFFFFFF,
				Vector2( widthEps, 1.0f + heightEps )
			},
		};

		GraphicsResourceManager *pManager = GraphicsResourceManager::GetInstance();
		VertexBufferDescription desc;
		String tempName;

		desc.bufferType = EVertexBufferType::STATIC;
		desc.primitiveType = EPrimitiveType::TRIANGLE_STRIP;
		desc.vertexSize = PSX_SizeOf( Vertex2D );
		desc.numVertices = 4;
		desc.numPrimitives = 2;
		desc.pData = quad;
		desc.pDecl = pManager->CreateVertexDeclaration;

		tempName.Format( "ScreenOverlayVB%i", this );
		m_pVB = pManager->CreateVertexBuffer( tempName.GetCString(), &desc );

		// TODO: Not finished

		return EErrorCode::NONE;

	}

	void ScreenOverlay::Cleanup( void )
	{


	}
}

#endif /* PSX_PLATFORM_WINDOWS_WINDOW */
